<?php

/**
 * Utility Funtions
 * 
 * @author: Victor Nava
 * @author: Eduardo Nava
 */


/**
 * Helpler to redirect to a url
 * 
 * @param $url
 * @return void
 */
function redirect($url){
	header( 'Location: '.$url);
	exit();
}



/**
 * Gets the rating element of venue, beer, etc. (the 5 beers icons)
 *  
 * @param $controller
 * @param $id
 * @param $rating
 * @return String html
 */
function getRatingElement($controller,$id,$rating){
	$fullImg = "../img/beer_glass_full_24.png";
	$emptyImg = "../img/beer_glass_unfull_24.png";
	$elem = '<span class="rating">';
	
	for ($i=0; $i<5; $i++){
		$rate_level=$i+1;
		if ((int)$rating > $i){
			
			$elem .= "<a href=\"router.php?c=$controller&a=rate&id=$id&rate_level_id=$rate_level\" <img class='rating-glass' src=\"$fullImg\"/></a>";
			//$elem .= "<img src=\"$fullImg\"/>";
		}else{
			
			$elem .= "<a href=\"router.php?c=$controller&a=rate&id=$id&rate_level_id=$rate_level\" <img class='rating-glass' src=\"$emptyImg\"/></a>";
			//$elem .= "<img src=\"$emptyImg\"/>";
		}
	}
	$elem .= '</span>';
	return $elem;
}


/**
 * Convert a number from 1 to 7 to a day of the week
 * 
 * @param $repeats
 * @return String day of week
 */
function getOfferRepeatDays($repeats){
	$DaysString="";
	$days = array();
	$arrString = str_split($repeats);
	foreach ($arrString as $char){
		switch ($char) {
			case "1":
				$days[] = "Mon";
				break;
			case "2":
				$days[] = "Tue";
				break;
			case "3":
				$days[] = "Wed";
				break;
			case "4":
				$days[] = "Thu";
				break;
			case "5":
				$days[] = "Fri";
				break;
			case "6":
				$days[] = "Sat";
				break;
			case "7":
				$days[] = "Sun";
				break;
		}
	}
	return implode(", ", $days);
}
?>